package com.farsight.leo.fssmartlock.activities;

import android.content.Context;
import android.content.Intent;
import android.widget.ListView;

import com.farsight.leo.fssmartlock.R;
import com.farsight.leo.fssmartlock.adapters.AuthCodeListAdapter;
import com.farsight.leo.fssmartlock.bases.BaseActivity;
import com.farsight.leo.fssmartlock.bases.BaseApplication;
import com.farsight.leo.fssmartlock.db.AuthCodeEntity;
import com.farsight.leo.fssmartlock.db.DeviceEntity;
import com.farsight.leo.fssmartlock.net.bean.UserData;
import com.farsight.leo.fssmartlock.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class AuthCodeListActivity extends BaseActivity {

    private ListView mListView;
    private ArrayList<AuthCodeEntity> mList = new ArrayList<>();
    private AuthCodeListAdapter mAdapter;

    public static void start(Context context) {
        Intent starter = new Intent(context, AuthCodeListActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected int set_layout_id() {
        return R.layout.activity_auth_code_list;
    }

    @Override
    protected void initData() {
        UserData userData = BaseApplication.getUserData();
        if (userData == null) {
            return;
        }
        DeviceEntity deviceEntity = BaseApplication.getDeviceDb().getDeviceDao().query(userData.getUser_id());
        List<DeviceEntity> deviceEntities = BaseApplication.getDeviceDb().getDeviceDao().queryAll(userData.getUser_id());
        for(DeviceEntity entity:deviceEntities){
            LogUtils.log(entity.toString());
        }
        if (deviceEntity == null) {
            return;
        }
        LogUtils.log(deviceEntity.toString());
        List<AuthCodeEntity> entities = BaseApplication.getDeviceDb().getAuthCodeDao().query(userData.getUser_id(), deviceEntity.getId());
        mList.addAll(entities);
    }

    @Override
    protected void initView() {
        mListView = findViewById(R.id.activity_auth_code_list_lstv_code_list);
        mListView.setDividerHeight(0);
        mAdapter = new AuthCodeListAdapter(mList, this);
        mListView.setAdapter(mAdapter);

    }

    @Override
    protected void initListeners() {

    }
}
